#include "newstockdialog.h"
#include "ui_newstockdialog.h"

#include <QDebug>

NewStockDialog::NewStockDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::NewStockDialog)
{
    ui->setupUi(this);
}

NewStockDialog::NewStockDialog(Stock *s, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::NewStockDialog)
{
    ui->setupUi(this);
    this->s=s;
}

NewStockDialog::~NewStockDialog()
{
    delete ui;
}

void NewStockDialog::accept()
{
    qDebug()<<"OK-Button clicked";

    /*check, if all is set*/
    if(s!=NULL && !ui->stockNameEdit->text().isEmpty() && !ui->stockSymbolEdit->text().isEmpty())
    {
        /*add a new stock*/
        qDebug()<<"Adding new stock("<<ui->stockNameEdit->text()<<","<<ui->stockSymbolEdit->text()<<")";
        s->addStock(ui->stockNameEdit->text(),ui->stockSymbolEdit->text());
    }

    hide();
}
